from rest_framework.decorators import action
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response

from apps.meiduo_admin.serialziers.groups import GroupsSerializer
from apps.meiduo_admin.serialziers.perms import PermissionSerializer
from apps.meiduo_admin.utils import NumPage
# djang的分组模型类
from django.contrib.auth.models import Group, Permission


class GroupsView(ModelViewSet):
    # 指定查询集
    queryset = Group.objects.all()
    # 指定序列化器
    serializer_class = GroupsSerializer
    # 指定权限
    permission_classes = [IsAdminUser]
    # 指定分页
    pagination_class = NumPage

    # 获取简单权限
    def simple(self, request):
        # 获取所有权限
        perms = Permission.objects.all()
        # 返回权限
        ser = PermissionSerializer(perms, many=True)
        return Response(ser.data)
